export default{
  namespaced: true,

  state: {
    token:uni.getStorageSync('token')||'123456',//请求有问题随便写一个token
    address:uni.getStorageSync('address')||{},//收货详细地址
    userinfo:uni.getStorageSync('userinfo')||{},//用户信息
    redirectInfo: null // 重定向的信息对象，包含属性： { url, type }
  },
  mutations: {
    //收货地址存储持久化本地
    setAddress(state,res){
      state.address=res
      uni.setStorageSync('address',res)
    },
    //用户信息
    updateUserInfo(state,userinfo){
      state.userinfo=userinfo
      uni.setStorageSync('userinfo',userinfo)
    },
    //存储token
    setToken(state,token){
      state.token=token
      uni.setStorageSync('token',token)
    },
    //退出登录
    logout(state){
      console.log("删除",state);
      state.token='',
      state.address={}
      state.userinfo={}
    },
    //存储路径
    setredirectInfo(state,url){
      state.redirectInfo=url
    }
  },
  getters: {
      // 收货详细地址的计算属性
  fullAddress(state) {
    const { provinceName, cityName, countyName, detailInfo } = state.address;
    if (!provinceName) return "";
    // 拼接 省，市，区，详细地址 的字符串并返回给用户
    return provinceName + cityName + countyName + detailInfo;
  },
  },

  actions: {},
}